<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>state</title>
</head>

<body>
    <!-- 准备好一个容器 -->
    <div id="test"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">  /*此处一定要写babel*/
        //1.创建组件
        class Weather extends React.Component {
            constructor(props) {
                super(props)
                this.state = { isHot: false,wind:'微风'}
                this.changeWeather = this.changeWeather.bind(this)
            }

            render() {
                //读取状态
                const { isHot ,wind} = this.state
                console.log(this)
                return <h1 onClick={this.changeWeather}>今天天气很{isHot ? '炎热' : '凉爽'},{wind}</h1>
            }

            changeWeather() {
                //获取原来的ishot
                const isHot = this.state.isHot;
                //状态 state不可直接更改 需要借助内置api更改
                // this.state.isHot = !isHot; 错误写法

                //状态必须通过setState进行更改
                this.setState({isHot:!isHot})
            }
        }

        //2.渲染组件
        ReactDOM.render(<Weather />, document.getElementById("test"))


    </script>
</body>

</html>